package com.gusto.engine.clusterant.graph;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class ScatterPlotGraph {
	
	public static JFreeChart getPoints(XYSeries series) {
		XYSeriesCollection seriesColl = new XYSeriesCollection(series);
		return getPointsImpl(seriesColl);
	}
	
	public static JFreeChart getPoints(XYSeriesCollection series) {
		return getPointsImpl(series);
	}
	/*
	public static JFreeChart getPoints() {
		XYSeries series1 = new XYSeries("Test Data");
        series1.add(3, 4);
        series1.add(1, 8);
        series1.add(6, 2);  // really large value
        series1.add(5, 5);
        series1.add(4, 1);
        series1.add(7, 5);
        
        XYSeries series2 = new XYSeries("Test Data");
        series2.add(6, 4);
        series2.add(3, 8);
        
        XYSeriesCollection series = new XYSeriesCollection();
        series.addSeries(series1);
        series.addSeries(series2);
		return getPointsImpl(series);
	}
	*/
	public static JFreeChart getPointsImpl(XYSeriesCollection series) {
		XYDataset data = series;//new XYSeriesCollection(series);
        JFreeChart chart = ChartFactory.createScatterPlot(
            "Scatter Plot Demo 3",
            "", "", 
            data, 
            PlotOrientation.VERTICAL,
            false, 
            false, 
            false
        );
        /*
        XYPlot plot = chart.getXYPlot();
        XYDotRenderer xyRenderer = new XYDotRenderer();
        xyRenderer.setBaseFillPaint(Color.BLUE);
        xyRenderer.setBaseFillPaint(Color.BLUE);
        plot.setRenderer(xyRenderer);
        plot.setDomainCrosshairVisible(false);
        plot.setRangeCrosshairVisible(false);

        NumberAxis domainAxis2 = (NumberAxis) plot.getDomainAxis();
        domainAxis2.setAutoRangeIncludesZero(false);
        */
        NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis();
        domainAxis.setAutoRangeIncludesZero(false);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setVerticalAxisTrace(true);
        chartPanel.setHorizontalAxisTrace(true);
        //chartPanel.setVerticalZoom(true);
        //chartPanel.setHorizontalZoom(true);
        //setContentPane(chartPanel);
    	return chart;
	}
	
}
